﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using RedHouse.Data.Service;
using RedHouse.Data.Base;

namespace RedHouse.AdminControl
{
    public partial class SlideShow : System.Web.UI.Page
    {
        public int Action { get; set; }
        public int Id { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["Action"] != null)
                {
                    Action = int.Parse(Request.QueryString["Action"].ToString());
                }               

                Initialize();
            }
        }

        private void Initialize()
        {

            switch (Action)
            {
                case 1:
                    SlideShowDetail.Visible = true;
                    SlideShowList.Visible = false;
                    if (Request.QueryString["Id"] != null)
                    {
                        Id = int.Parse(Request.QueryString["Id"].ToString());
                        SlideShowDetail.BindSlideShowDetail(Id);
                    }

                    break;
                case 2:
                    SlideShowDetail.Visible = false;
                    SlideShowList.Visible = true;
                    break;
                default:
                    break;
            }
        }



        [WebMethod]
        public static void DeleteItem(string id)
        {
            int slideShowId = int.Parse(id);
            ISlideShowService _service = new SlideShowService();
            _service.DeleteSlideShow(slideShowId);
        }

        //[WebMethod()]
        //public static string EditNews(string id)
        //{
        //    string jSonString = string.Empty;
        //    try
        //    {
        //        Guid newsId = new Guid(id);
        //        INewsService newsService = new NewsService();
        //        JavaScriptSerializer serializer = new JavaScriptSerializer();
        //        RedHouseNews news = newsService.GetNewsById(newsId);
        //        jSonString = serializer.Serialize(news);
        //    }
        //    catch (Exception ex)
        //    {
        //        return jSonString;
        //    }
        //    return jSonString;
        //}

        //[WebMethod()]
        //public static string SaveNews(object news)
        //{
        //    try
        //    {
        //        RedHouseNews redHouseNews = GetRedHouseNews(news);
        //        NewsService.Instance.UpdateNews(redHouseNews);
        //        return "save successfully!";
        //    }
        //    catch (Exception ex)
        //    {
        //        return ex.Message;
        //    }
        //}

        //public static RedHouseNews GetRedHouseNews(object news)
        //{
        //    RedHouseNews retNews = new RedHouseNews();
        //    Dictionary<string, object> tmp = (Dictionary<string, object>)news;
        //    object id = null;
        //    object location = null;
        //    object category = null;
        //    object lang = null;
        //    object des = null;
        //    object imageUrl = null;
        //    object title = null;
        //    object startDate = null;
        //    object endDate = null;

        //    tmp.TryGetValue("Id", out id);
        //    tmp.TryGetValue("Location", out location);
        //    tmp.TryGetValue("Category", out category);
        //    tmp.TryGetValue("LangId", out lang);
        //    tmp.TryGetValue("Description", out des);
        //    tmp.TryGetValue("ImageUrl", out imageUrl);
        //    tmp.TryGetValue("Title", out title);
        //    tmp.TryGetValue("StartDate", out startDate);
        //    tmp.TryGetValue("EndDate", out endDate);
        //    retNews.NewsDetail = new Data.Detail();
        //    retNews.NewsDetail.Title = title.ToString();
        //    retNews.Id = new Guid(id.ToString());
        //    retNews.NewsDetail.LangID = new Guid(lang.ToString());
        //    retNews.CategoryId = new Guid(category.ToString());
        //    retNews.LocationId = int.Parse(location.ToString());
        //    retNews.LangId = new Guid(lang.ToString());
        //    retNews.NewsDetail.Description = des.ToString();
        //    retNews.NewsDetail.ImageUrl = imageUrl.ToString();
        //    retNews.CreatedDate = DateTime.Now;
        //    retNews.CreatedBy = "admin";
        //    retNews.NewsGroup = RedHouseGroup.GroupList[0].Value;

        //    DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
        //    dtfi.ShortDatePattern = "MM/dd/yyyy";
        //    dtfi.DateSeparator = "/";

        //    retNews.StartDate = DateTime.Parse(startDate.ToString(), dtfi);
        //    retNews.EndDate = DateTime.Parse(endDate.ToString(), dtfi);
        //    //retNews.DisplayOrder = int.Parse(order.ToString());
        //    return retNews;
        //}
    }
}